from iteration_helpers import update
import networkx as nx
import pandas as pd

def run_iterations(G, total_iterations=4000, record_interval=25,
                   broker_type="N/A", model_type="N/A"):
    assortativity_values = []
    iterations = []

    for i in range(total_iterations):
        update(G)

        # Every `record_interval` iterations, record the assortativity coefficient
        if (i + 1) % record_interval == 0:
            assortativity = nx.attribute_assortativity_coefficient(G, 'identity')
            assortativity_values.append(assortativity)
            iterations.append(i + 1)
    
    assort_df = pd.DataFrame({
        'Iteration': iterations,
        'Assortativity': assortativity_values
    })
    filename = f"{broker_type}_{model_type}.csv"
    assort_df.to_csv(filename, index=False)
            
